<?

//根据页面数量信息，筛选信息，创造url，供页码,跳转等使用
include_once("model/set_url.php");


//获取数据
//print_r2($_REQUEST);





//将本身有的任务，整理一下。
//区分日报名字，和日报任务

//先插入报告，再插入报告任务
    
    $_report['ai_name']          = $_REQUEST['ai_name'];
    $_report['ai_date']          = date("Y-m-d h:s:i");
    $_report['ai_employee_name'] = $_SESSION['nid'];
    $_report['ai_employee_nid']  = $_SESSION['nid'];


foreach ($_REQUEST['task_nid'] as $key => $value)
{


    $_report_task[$key]['task_nid']  = $value;
    $_report_task[$key]['task_remark']    = $_REQUEST['remark'][$value];
    $_report_task[$key]['task_case']      = $_REQUEST['case'][$value];
    $_report_task[$key]['task_status']    = $_REQUEST['status'][$value];
    $_report_task[$key]['task_name'] = $_REQUEST['task_name'][$value];

    $_report[$key]['authur'] = $_SESSION['nid'];
    $_report[$key]['ip'] = $_SERVER["REMOTE_ADDR"] ;
}


$p['table']=$table_Prefix."daily_report_task";
$p['items']=['title', 'task_nid', 'task_remark', 'task_case', 'task_status','task_name', 'authur', 'ip'];
$p['values']=$_report;
$sql=insert_datas($p);
$query = mysql_query($sql) or die ("error:".mysql_error());



//第二步，把新建的工作也插进来

//    [ai_new_task] => Array
//        (
//            [0] => n1
//            [1] => n2
//        )
//    [ai_new_status] => Array
//        (
//            [0] =>
//            [1] =>
//        )
////    [ai_new_case] => Array
////        (
////            [0] =>
////            [1] =>
////        )
//    [ai_new_remark] => Array
//        (
//            [0] => 111
//            [1] => 222
//        )
foreach ($_REQUEST['ai_new_task'] as $k => $v)
{
    if($v){
    $_new_report[$k]['title']       = $_REQUEST['ai_name'];
    $_new_report[$k]['task_remark'] = $_REQUEST['ai_new_remark'][$k];
    $_new_report[$k]['task_case']   = $_REQUEST['ai_new_case'][$k];
    $_new_report[$k]['task_status'] = $_REQUEST['ai_new_status'][$k];
    $_new_report[$k]['task_name']   = $_REQUEST['ai_new_task'][$k];
    $_new_report[$k]['authur']      = $_SESSION['nid'];
    $_new_report[$k]['ip']          = $_SERVER["REMOTE_ADDR"];
    }

}


$pp['table']=$table_Prefix."daily_report";
$pp['items']=['title','task_remark', 'task_case', 'task_status','task_name', 'authur', 'ip'];
$pp['values']=$_new_report;
$sql=insert_datas($pp);


$query = mysql_query($sql) or die ("error:".mysql_error());


//第三步，把新建的工作，插入任务中


foreach ($_REQUEST['ai_new_task'] as $k => $v)
{
    if($v){

//        circulate
//        priority
//        enddate


        $_new_task[$k]['title'] = $_REQUEST['ai_name'];
        $_new_task[$k]['note'] = $_REQUEST['ai_new_remark'][$k];
        $_new_task[$k]['case_id'] = $_REQUEST['ai_new_case'][$k];
        $_new_task[$k]['status'] = $_REQUEST['ai_new_status'][$k];
        $_new_task[$k]['principal'] = $_SESSION['nid'];
        $_new_task[$k]['authur'] = $_SESSION['nid'];
        $_new_task[$k]['ip'] = $_SERVER["REMOTE_ADDR"];
        $_new_task[$k]['circulate'] = "普通";
        $_new_task[$k]['priority'] = "普通";
        $_new_task[$k]['is_repeat'] = "0";
        $_new_task[$k]['enddate'] = date("Y-m-d h:s:i", strtotime("+1 day"));

    }

}

$ppp['table']=$table_Prefix."task";
$ppp['items']=['title','remark', 'case_id', 'status','principal', 'authur', 'ip','circulate','priority','is_repeat','enddate',];
$ppp['values']=$_new_task;


//print_r2($ppp);

$sql=insert_datas($ppp);
$query = mysql_query($sql) or die ("error:".mysql_error());

?>

<script type="text/javascript">
    alert("输入信息已保存，点击确认返回继续操作.");
    document.location.href = "data_list.php?nav-itemed=daily_report";
</script>

